home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 9291 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.2 KB

  1. Path: rcp6.elan.af.mil!rscernix!danpop
  2. From: danpop@mail.cern.ch (Dan Pop)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Schildt <- Advanced Books
  5. Date: 8 Mar 96 20:47:04 GMT
  6. Organization: CERN European Lab for Particle Physics
  7. Message-ID: <danpop.826318024@rscernix>
  8. References: <8BA8405.02C70020DE.uuout@sourcebbs.com> <danpop.826121528@rscernix> <1996Mar7.162150.115560@kuhub.cc.ukans.edu>
  9. NNTP-Posting-Host: ues5.cern.ch
  10. X-Newsreader: NN version 6.5.0 #7 (NOV)
  11.  
  12. In <1996Mar7.162150.115560@kuhub.cc.ukans.edu> anh@kuhub.cc.ukans.edu writes:
  13.  
  14. >Er, so what do you use instead of %d ?
  15.  
  16. %d, of course :-)
  17.  
  18. The clue is not to use a size_t value as a printf argument, because you
  19. simply cannot tell in advance what conversion specifier to use: %u or
  20. %lu.  Cast the size_t to any type you want and use the right conversion 
  21. specifier for that type: even %d will do.
  22.  
  23. Note that %d can be used with an uncast size_t only on very exotic
  24. implementations, where sizeof(size_t) < sizeof(int).  In such a case,
  25. the compiler will promote the size_t value to int.  If size_t is
  26. defined as unsigned int, using %d invokes undefined behaviour.
  27.  
  28. Dan
  29. --
  30. Dan Pop
  31. CERN, CN Division
  32. Email: danpop@mail.cern.ch 
  33. Mail:  CERN - PPE, Bat. 31 R-004, CH-1211 Geneve 23, Switzerland
  34.